﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BabyLearnEnglish_srcum_demo
{
    public class question
    {
        string url;

        public string Url
        {
            get { return url; }
            set { url = value; }
        }
        string result;

        public string Result
        {
            get { return result; }
            set { result = value; }
        }
        int score;

        public int Score
        {
            get { return score; }
            set { score = value; }
        }

        public question()
        {
            url = "";
            result = "";
            score = 0;
        }

        public question(string _line)
        {
            string[] arr = _line.Split('|');
            url = arr[0];
            result = arr[1];
            score = int.Parse(arr[2]);
        }

        public List<question> getList()
        {
            List<question> list = new List<question>();

            int counter = 0;
            string line;

            // Read the file and display it line by line.
            System.IO.StreamReader file = new System.IO.StreamReader("../../data/data.txt");
            while ((line = file.ReadLine()) != null)
            {
                question q = new question(line);
                list.Add(q);
                counter++;
            }

            file.Close();

            // Suspend the screen.

            return list;
        }

        public void saveList(List<question> _list)
        {
            System.IO.StreamWriter file = new System.IO.StreamWriter("../../data/data.txt");
            foreach (question q in _list)
            {
                string line = q.url + '|' + q.result + '|' + q.score;
                file.WriteLine(line);
            }
            file.Close();
        }

    }
}
